﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="EditLendProduct.aspx.cs" Inherits="MonkeyWarranty.Web.WarrantyTickets.EditLendProduct" %>
<%@ Import Namespace="Resources" %>
<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server">
    <title>
        <%=GlobalStrings.WarrantyTicketForm %> - <%=GlobalStrings.LendProduct %></title>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
     <h2><%=GlobalStrings.InstantTicketForm %>: <%=GlobalStrings.LendProduct %></h2>
    <p></p>
    <span class="failureNotification">
        <asp:Literal ID="lblErrorMessage" runat="server"></asp:Literal></span>
    
    <div style="min-width: 960px;">
        <fieldset class="register">
            <div style="float: left;margin-right: 50px;">
                <p>
                    <asp:HiddenField ID="hidProductId" runat="server" />
                    <%=GlobalStrings.Code %>
                    <asp:TextBox ID="txtCode" runat="server" ReadOnly="True" CssClass="textEntry codeprefix"></asp:TextBox>
                    <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="txtCode"
                        CssClass="failureNotification" ValidationGroup="AddNew">(*)</asp:RequiredFieldValidator>
                    <%=GlobalStrings.Name%>
                    <asp:TextBox ID="txtName" runat="server" ReadOnly="True" CssClass="textEntry name"></asp:TextBox>
                    <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ControlToValidate="txtName"
                        CssClass="failureNotification" ValidationGroup="AddNew">(*)</asp:RequiredFieldValidator>
                    <a href="javascript:void(0);" onclick="javascript:SelectProduct();">Select</a>  
                </p>

                <div id="products-dialog-form" title="<%=GlobalStrings.ProductsList %>">
                    <div class="filtering">
                        <label>
                            <%=GlobalStrings.Name %>:
                            <input type="text" name="name" id="name" /></label>
                        <label>
                            <%=GlobalStrings.ProductGroups %>:
                            <asp:DropDownList ID="ddlProductGroups" runat="server">
                            </asp:DropDownList>
                        </label>
                        <label>
                            <%=GlobalStrings.Manufacturers %>:
                            <asp:DropDownList ID="ddlManufacturers" runat="server">
                            </asp:DropDownList>
                        </label>
                        <button type="submit" id="LoadRecordsButton"><%=GlobalStrings.LoadRecords %></button>
                    </div>
                    <div id="ProductsTableContainer"></div>
                    <p><a href="../Products/New.aspx" target="_blank"><%=GlobalStrings.AddNew %></a></p>
                </div>
                
                <p>
                    <label><%=GlobalStrings.LendDate %></label><asp:TextBox ID="txtLendDate" runat="server" CssClass="textEntry date"></asp:TextBox>
                </p>
                <p><label><%=GlobalStrings.WarrantyProduct %></label><asp:DropDownList ID="ddlWarrantyProducts" runat="server"></asp:DropDownList></p>
                <p>
                    <label><%=GlobalStrings.Model %></label><asp:TextBox ID="txtModel" runat="server" CssClass="textEntry name"></asp:TextBox>
                </p>
                <p>
                    <label><%=GlobalStrings.Serial %></label><asp:TextBox ID="txtSerial" runat="server" CssClass="textEntry"></asp:TextBox>
                </p>
                <p><label><%=GlobalStrings.Quantity %></label><asp:TextBox ID="txtQuantity" runat="server" CssClass="textEntry codeprefix" Text="1"></asp:TextBox></p>
            </div>

            <div style="float: left;">
                <p><label><%=GlobalStrings.LendEmployee %></label><asp:DropDownList ID="ddlEmployees" runat="server"></asp:DropDownList></p>
                <p><label><%=GlobalStrings.Manufacturers %></label><asp:DropDownList ID="ddlManufacturers1" runat="server"></asp:DropDownList></p>
                <p><label><%=GlobalStrings.Description %></label><asp:TextBox ID="txtDescription" runat="server" TextMode="MultiLine" CssClass="textEntry description"></asp:TextBox></p>
                <p><label><%=GlobalStrings.Note %></label><asp:TextBox ID="txtNote" TextMode="MultiLine" runat="server" CssClass="textEntry description"></asp:TextBox></p>
            </div>
        </fieldset>
    </div>
    <p></p>
    <div>
        <input id="btnCancel" type="button" value="<%=GlobalStrings.Cancel %>"
            class="submitButton" onclick="javascript:window.location='Edit.aspx?id=<%=TicketId %>#tabs-2';" />
        <asp:Button ID="btnSave" runat="server" Text="<%$ Resources:GlobalStrings, Save %>"
            CssClass="submitButton" ValidationGroup="AddNew" OnClick="btnSave_Click" />
    </div>
    
    <script type="text/javascript">
        $(document).ready(function () {
            $("#<%=txtName.ClientID %>").prop("disabled", true);
            $("#<%=txtCode.ClientID %>").prop("disabled", true);
            $("#<%=txtLendDate.ClientID %>").calendar({ timeSeparators: null });

            $("#dialog:ui-dialog").dialog("destroy");
            $("#products-dialog-form").dialog({
                autoOpen: false,
                height: 400,
                width: 800,
                modal: true
            });

            //Prepare jtable plugin
            $('#ProductsTableContainer').jtable({
                paging: true,
                pageSize: 10,
                sorting: true,
                defaultSorting: 'Name ASC',
                actions: {
                    listAction: '../Products/List.aspx/ProductListByFilter'
                },
                fields: {
                    Id: {
                        key: true,
                        create: false,
                        edit: false,
                        list: false
                    },
                    Code: {
                        title: '<%=GlobalStrings.Code %>',
                        list: false
                    },
                    Name: {
                        title: '<%=GlobalStrings.Name %>',
                        width: '20%',
                        //inputClass: 'validate[required]'
                        display: function (data) {
                            return '<a href="javascript:void(0);" onclick="javascript:ProductSelect({Id:' + data.record.Id +
                            ',Code:\'' + data.record.Code + '\'' +
                                ',Name:\'' + data.record.Name + '\'' +
                                    '});">' + data.record.Name + '</a>';
                        }
                    }
                },
                //Initialize validation logic when a form is created
                formCreated: function (event, data) {
                    data.form.validationEngine();
                },
                //Validate form when it is being submitted
                formSubmitting: function (event, data) {
                    return data.form.validationEngine('validate');
                },
                //Dispose validation logic when form is closed
                formClosed: function (event, data) {
                    data.form.validationEngine('hide');
                    data.form.validationEngine('detach');
                }
            });

            //Re-load records when user click 'load records' button.
            $('#LoadRecordsButton').click(function (e) {
                e.preventDefault();
                $('#ProductsTableContainer').jtable('load', {
                    name: $('#name').val(),
                    productGroupId: $('#<% = ddlProductGroups.ClientID %>').val(),
                    manufacturerId: $('#<% = ddlManufacturers.ClientID %>').val()
                });
            });
        });
    </script>
    
    <script type="text/javascript">
        function ProductSelect(product) {
            $("#products-dialog-form").dialog("close");
            //console.debug(customer);
            $("#<%=hidProductId.ClientID %>").val(product.Id);
            $("#<%=txtName.ClientID %>").val(product.Name);
            $("#<%=txtCode.ClientID %>").val(product.Code);
        }

        function SelectProduct() {
            // load data
            $("#products-dialog-form").dialog("open");
            $('#LoadRecordsButton').click();
        }
    </script>
</asp:Content>
